package cn.micai.base.asyn;

import java.util.Random;

/**
 * 描述：
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/11 14:07
 */
public class MasterWorkerTest {

    public static void main(String [] args) {

        MasterDemo masterDemo = new MasterDemo(new WorkerDemo(), 10);

        for (int i = 0; i < 100; i++) {
            TaskDemo taskDemo = new TaskDemo();
            taskDemo.setId(i);
            taskDemo.setName("任务" + i);
            taskDemo.setPrice(new Random().nextInt(10000));
            masterDemo.submit(taskDemo);
        }

        masterDemo.execute();

        while (true) {
            if (masterDemo.isComplete()) {
                System.out.println("执行的结果为: " + masterDemo.getResult());
                break;
            }
        }

    }
}
